using System;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
    public class PhoneComparer : IComparer<PhoneInfo>
    {
        private string _sortExpression;
        public string SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

		private string _sortDirection;
        public string SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }

        public PhoneComparer(string sortExpression)
        {
            int iSplitPos = sortExpression.IndexOf(" ");
            SortExpression = (iSplitPos > 0) ? sortExpression.Substring(0, iSplitPos) : sortExpression;
            SortDirection = (iSplitPos > 0) ? sortExpression.Substring(iSplitPos + 1).ToUpper() : "ASC";
        }

        public PhoneComparer(string sortExpression, string sortDirection)
        {
            this.SortExpression = sortExpression;
            this.SortDirection = sortDirection;
        }

        int IComparer<PhoneInfo>.Compare(PhoneInfo x, PhoneInfo y)
        {
            PhoneInfo oX = (SortDirection == "ASC") ? x : y;
            PhoneInfo oY = (SortDirection == "ASC") ? y : x;

            switch (SortExpression)
            {				
				case "PhoneId":
					return oX.PhoneId.CompareTo(oY.PhoneId);				
				case "MacAddress":
					return oX.MacAddress.CompareTo(oY.MacAddress);				
				case "UserId":
					return oX.UserId.CompareTo(oY.UserId);				
				case "ConfigurationId":
					return oX.ConfigurationId.CompareTo(oY.ConfigurationId);				
				case "IpAddress":
					return oX.IpAddress.CompareTo(oY.IpAddress);				
				case "SubnetId":
					return oX.SubnetId.CompareTo(oY.SubnetId);				
				case "SerialNumber":
					return oX.SerialNumber.CompareTo(oY.SerialNumber);				
				case "UserAgent":
					return oX.UserAgent.CompareTo(oY.UserAgent);				
				case "ModelId":
					return oX.ModelId.CompareTo(oY.ModelId);				
				case "Model":
					return oX.Model.CompareTo(oY.Model);				
				case "FirmwareId":
					return oX.FirmwareId.CompareTo(oY.FirmwareId);				
				case "Firmware":
					return oX.Firmware.CompareTo(oY.Firmware);				
				case "BootLoader":
					return oX.BootLoader.CompareTo(oY.BootLoader);				
				case "Extension":
					return oX.Extension.CompareTo(oY.Extension);				
				case "FirstFailedDate":
					return oX.FirstFailedDate.CompareTo(oY.FirstFailedDate);				
				case "RegistrationFailed":
					return oX.RegistrationFailed.CompareTo(oY.RegistrationFailed);				
				case "ReRegisterCount":
					return oX.ReRegisterCount.CompareTo(oY.ReRegisterCount);				
				case "HttpClientPass":
					return oX.HttpClientPass.CompareTo(oY.HttpClientPass);				
				case "CreatedDate":
					return oX.CreatedDate.CompareTo(oY.CreatedDate);				
				case "UpdatedDate":
					return oX.UpdatedDate.CompareTo(oY.UpdatedDate);
				default:
                    return 0;
            }
        }
    }
}
